$(document).ready(function() {	
	//iRent();
	item_board();
});
function item_board(){
	rule1 = $("#item_board");
	rule1.empty();
	$.ajax({
		type:"post",
		url:"ruleAction!findAll",
		//data:{"keyword":value1},
		dataType:"json",
		success:function(result){
			//alert(result);
		    if(result == ""){
		    	rule1.empty();
		    	rule1.append('<p>暂无上传物品规则/p>');
			}else{
				//alert("2222222222");		
				var result1=result.rule;
				$.each(result1,function(){
					e=this.content;
				});
				rule1.append(e);		
			}
			//重新渲染
		},
		error:function(err){		
			alert(err.message);
		}
	});
}
//发布物品出租信息
function iRent() {
	//规则
	//alert("iRent");
	
	//发布出租
	//var itemId= 1;
	var itemName= $("#itemName").val();
	var PtypeName=$("#item_pType").find('option:selected').text(); 
	var itemTypeName=$("#item_type").find('option:selected').text(); 
	var itemPrice= $("#itemPrice").val();
	var itemNumber= $("#itemNumber").val();
	var itemDiscription= $("#itemDiscription").val();
	alert(itemName+" "+PtypeName+" "+itemTypeName+" "+itemPrice+" "+itemNumber+" "+itemDiscription);
	
	$.ajax({
		type:"post",
		url:"itemTableAction!addItemTable",
		data:{"itemName":itemName,"PtypeName":PtypeName,"itemTypeName":itemTypeName,"itemPrice":itemPrice,"itemNumber":itemNumber,"itemDiscription":itemDiscription},
		dataType:"json",
		success:function(result){
			//alert(result);
		    if(result!=null&&result.code=="003"){
		    	alert(result.msg);
		    	window.location.href = "main.jsp";
		    }else if(result.code == "002"){
		    	alert("exception:"+result.msg);
		    	window.location.href = "main.jsp";
			}else{
		    window.location.href = "main.jsp";
			}
		},
		error:function(err){		
			alert("error:"+err.message);
		}
	});

}
function uploadPicture(){
	
       //alert("uploadPicture");
            var file = $("#upload").val();  
            if (file.length > 0) {
            var fileType = file.substring(file.lastIndexOf(".")+1);
            if(fileType!="png"&&fileType!="jpg"&&fileType!="jpeg"&&fileType!="bmp"){
            alert("请上传图片文件");
            return ;
            } 
                ajaxFileUpload();
            }
            else {
                alert("请选择图片");
            }
        
}
function ajaxFileUpload() {
	//alert("ajaxFileUpload");
    $.ajaxFileUpload
    (
        {
            url: "pictureUploadAction!execute.action", //用于文件上传的服务器端请求地址
            secureuri: false, //一般设置为false
            fileElementId: 'upload', //文件上传空间的id属性  <input type="file" id="file" name="file" />
            dataType: "json", //返回值类型 一般设置为json
            success: function (data,status)  //服务器成功响应处理函数data,status
            {
            	//alert(data);
                //alert("upload success");
            	//alert(data.code);
            	//alert(data.path);
                if(data.code=="003")
                //alert(data.msg);
                //alert(data.msg);
                //$("#img1").attr("src", data);
                iRent();
            },
            error: function (data,status,e)//服务器响应失败处理函数data,status,e
            {
                alert("error:"+e);
            }
        }
    );
    return false;
}







